package examination_practice01;
class Point {
    double x;
    double y;
    public Point(double x,double y){
        this.x=x;
        this.y=y;
    }
    //计算两点之间的距离
    public double distance(Point point){
        double dx=x-point.x;
        double dy=y-point.y;
        return Math.sqrt(dx*dx+dy*dy);
    }
}
public class ClosestPairBF {
    //计算最接近点对的距离
    public static double closestPair(Point[] points){
        int n=points.length;//记录点数组的长度
        double minDistance =Double.POSITIVE_INFINITY;//初始值设置为无穷大
        //遍历所有点对
        for (int i=0; i< n;i++){
            for (int j=i+1;j<n;j++){//从i的后一个点开始遍历，并不断计算该点与i点的距离
                double distance=points[i].distance(points[j]);
                minDistance=Math.min(minDistance,distance);//选最小的值更新minDistance
            }
        }

        return minDistance;
    }
    public static void main(String[] args){
        Point[] points={new Point(0,0),
                new Point(1,1),
                new Point(1,1.5),
                new Point(2,3)
        };
        double minDistance=closestPair(points);
        System.out.println("最接近的距离为："+minDistance);
    }
}
